// pages/my/visitor/selectClass/selectClass.js
const app = getApp()
var base_url = app.globalData.url
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this 
    wx.getUserInfo({
      success: function (res) {
        console.log(res);
        // var avatarUrl = 'userInfo.avatarUrl';
        // var nickName = 'userInfo.nickName';
        // that.setData({
        //   avatarUrl: '../../../../images/headpic/head.png',
        // })
      }
    })
    wx.getSystemInfo({

      success: function (res) {
        let clientHeight = res.windowHeight;
        let clientWidth = res.windowWidth;
        let screenWidth = res.screenWidth;
        let ratio = 750 / clientWidth;
        let height = clientHeight * ratio;
        that.setData({
          height: clientHeight
        });
      }
    });


    wx.getStorage({
      key: 'schoolName',
      success: function (resl) {
        that.setData({
          school: resl.data
        })
      },
      fail: function (res) {

      }
    })
    wx.getStorage({
      key: 'teacherName',
      success: function (resl) {
        that.setData({
          name: resl.data
        })
      },
      fail: function (res) {

      }
    })
    wx.getStorage({
      key: 'teacherID',
      success: function (resl) {
        wx.request({
          url: base_url+'/getThisClasses/',
          method: 'POST',
          data: {
            teacherID: resl.data,
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          success: function (res) {
            if(res.data['flag'] == true){
              that.setData({
                classes_lst: res.data['classes_lst'],
                avatarUrl: res.data['headpic'],
                address: res.data['address'],
              })
            }
          }
        })
      },
      
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  student2addClass:function(res){
    wx.getStorage({
      key: 'student_id',
      success: function (resl) {
        wx.request({
          url: base_url+'/student2addClass/',
          method: 'POST',
          data: {
            student_id: resl.data,
            class_id:res.currentTarget.dataset.name
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          success: function (res) {
            if(res.data['flag'] == true){
              wx.showModal({
                title: '提示',
                content: '加入成功',
                showCancel: false,
                confirmText: '确定',
                success: function (res) {
                  wx.navigateTo({
                    url: '../mine/mine',
                    success: function (res) {
                      console.log(res)
                    },
                    fail: function () {
                    }
                  })
                }
              })
            }
          }
        })
      },
      fail: function (res) {

      }
    })
  },
  gotoback:function(){
    wx.navigateTo({
      url: '../addClass/addClass',
      success: function (res) {
        console.log(res)
      },
      fail: function () {
      }
    })
  }
})